package com.regent.central.bill.repository.mrp;

import com.regent.central.bill.core.mrp.BillMaterialReturn;
import com.regent.central.bill.repository.mrp.dto.billReturn.BillMaterialReturnPageParam;
import com.regent.central.bill.repository.mrp.dto.billReturn.detail.ActionMaterialReturnCollectQTO;
import com.regent.central.bill.repository.mrp.dto.billReturn.detail.ReturnDetailSkuQTO;
import com.regent.central.bill.repository.mrp.dto.billReturn.detail.ReturnDetailsSkuDTO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface BillMaterialReturnMapper extends Mapper<BillMaterialReturn> {

    /**
     * 查询本厂今天最大退料单号
     *
     * @param unitId
     * @param dateStart
     * @param dateEnd
     * @return
     */
    int countBillReturnByUnitId(@Param("unitId") String unitId, @Param("dateStart") LocalDateTime dateStart, @Param("dateEnd") LocalDateTime dateEnd);

    /**
     * 查询退料单物料信息列表
     * @param billMaterialReturnId
     * @return
     */
    List<ReturnDetailSkuQTO> listReturnActionDetail(@Param("billMaterialReturnId") String billMaterialReturnId);

    /**
     * 查询退料单收退款列表
     * @param billMaterialReturnId
     * @return
     */
    List<ActionMaterialReturnCollectQTO> listReturnActionCollect(@Param("billMaterialReturnId") String billMaterialReturnId);

    /**
     * 撤销退料单
     *
     * @param billMaterialReturnId 退料单ID
     */
    int undoBill(String billMaterialReturnId);

    /**
     * 撤销退料单的所有退料动作
     *
     * @param billMaterialReturnId 退料单ID
     */
    int undoReturnAction(String billMaterialReturnId);

    /**
     * 获取一个退料单的所有关联的流水ID
     *
     * @param billMaterialReturnId 退料单ID
     * @return 退料单ID列表
     */
    List<String> listRemittanceId(String billMaterialReturnId);

    /**
     * 获取退料单关联的库存变动记录
     *
     * @param billMaterialReturnId 退料单ID
     */
    String getStockChangeId(String billMaterialReturnId);

    /**
     * 按分页获取退料单的ids
     * @param param
     * @return
     */
    List<String> findIdsForPage(BillMaterialReturnPageParam param);

    /**
     * 退料单列表
     * @param returnIds
     * @return
     */
    List<ReturnDetailsSkuDTO> listReturnActionDetailByIds(@Param("returnIds") List<String> returnIds);

    /**
     * 退料单列表导出Excel
     * @param param
     * @return
     */
    List<ReturnDetailsSkuDTO> returnExcel(BillMaterialReturnPageParam param);
}